﻿@model ThaireInvestmentWeb.Models.EditUnitTrustSaleModel
@{
    ViewBag.Title = "Edit UnitTrustPurchase";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () {

        $("#TradeDate,#SettlementDate").datepicker(
            {
                dateFormat: 'dd/mm/yy',
                yearRange: "-30:+40",
                showOn: 'button',
                showAnim: 'fadeIn',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                buttonImage: '@Url.Content("~/Content/images/Calendar.png")', // '../../Content/images/Calendar.png',
            });
        $("#CancelBtn").click(function (event) {
            //showConfirm("Are you sure to cancel ?", CancelBtnAction);
            showConfirm(null, CancelBtnAction);
            return false;
        });
        $("#Unit").change(calAll);
        $("#PriceUnit").change(calAll);
        $("#ComRate").change(calAll);
        $("#VatRate").change(calAll);
        $("#WHTaxRate").change(calAll);
    });
        function CancelBtnAction(event) {
            window.location.href = 'EditUnitTrustHeader?headerId=@Model.HeaderID';
        }

        function calAll() {
            calGrossAmount();
            calComAmount();
            calVatAmount();
            calPurchaseValueNet();
            calWHTaxAmount();
            calNetSettle();
        }
        function calPurchaseValueNet() {
            var v1 = $("#Transaction_ComAmount").val();
            var v2 = $("#Transaction_GrossAmount").val();
            var v3 = $("#Transaction_VatAmount").val();
            if (v1 != '' && v2 != '' && v3 != '') {
                var total = parseFloat(v1.replace(',', '')) + parseFloat(v2.replace(',', '')) + parseFloat(v3.replace(',', ''));
                $('#Transaction_PurchaseValueNet').val(FormatNumber2(total));
            }
        }
        function calNetSettle() {
            var v1 = $("#Transaction_PurchaseValueNet").val();
            var v2 = $("#Transaction_WHTaxAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseFloat(v1.replace(',', '')) - parseFloat(v2.replace(',', ''));
                $('#Transaction_NetSettle').val(FormatNumber2(total));
            }
        }
        function calGrossAmount() {
            var v1 = $("#Unit").val();
            var v2 = $("#PriceUnit").val();
            if (v1 != '' && v2 != '') {
                var total = parseFloat(v1.replace(',', '')) * parseFloat(v2.replace(',', ''));
                $('#Transaction_GrossAmount').val(FormatNumber2(total));
            }
        }
        function calComAmount() {
            var v1 = $("#ComRate").val();
            var v2 = $("#Transaction_GrossAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseFloat(v1.replace(',', '')) * parseFloat(v2.replace(',', '')) / 100;
                $('#Transaction_ComAmount').val(FormatNumber2(total));
            }
        }
        function calVatAmount() {
            var v1 = $("#VatRate").val();
            var v2 = $("#Transaction_GrossAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseFloat(v1.replace(',', '')) * parseFloat(v2.replace(',', '')) / 100;
                $('#Transaction_VatAmount').val(FormatNumber2(total));
            }
        }

        function calWHTaxAmount() {
            var v1 = $("#WHTaxRate").val();
            var v2 = $("#Transaction_GrossAmount").val();
            if (v1 != '' && v2 != '') {
                var total = parseFloat(v1.replace(',', '')) * parseFloat(v2.replace(',', '')) / 100;
                $('#Transaction_WHTaxAmount').val(FormatNumber2(total));
            }
        }
</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instrument Type > <a href="@Url.Action("ManageUnitTrust", "UnitTrust", new { headerId = @Model.HeaderID })">Unit Trust</a> > <a href="@Url.Action("EditUnitTrustHeader", "UnitTrust", new { headerId = @Model.HeaderID })">Header</a> >Sale
            </div>
        </td>
    </tr>
</table>
<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" tyle="width: 100%; text-align: center;">INPUT Sale Unit Trust</td>
    </tr>
</table>
<table style="width: 100%; text-align: center;">
    <tr>
        <td>
            @Html.Partial("_UnitTrustHeaderView", Model.ScreenData.HeaderDTO)
            @Html.ValidationSummary(true)
            @using (Html.BeginForm("EditSaleTransaction", "UnitTrust", FormMethod.Post, new { id = "mainForm" }))
            {

                <table style="margin-top: 20px;" class="tableform" width="100%" border="5" align="center" cellspacing="2">
                    <tr>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Transaction Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedTransactionType, Model.TransactionTypeList)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Ref. No.<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.EditorFor(model => model.RefNo)
                            @Html.ValidationMessageFor(model => model.RefNo)</td>
                        <td>
                            <div align="right">Type of Payment<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedTypeOfPayment, Model.TypeOfPaymentList)
                            @Html.ValidationMessageFor(model => model.SelectedTypeOfPayment)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Trade Date<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.TradeDate, new {  style = "width: 80px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.TradeDate) })
                            @Html.ValidationMessageFor(model => model.TradeDate)  (Ex.31/12/2014)</td>
                        <td>
                            <div align="right">Settlement Date<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.SettlementDate, new {  style = "width: 80px;", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.SettlementDate) })
                            @Html.ValidationMessageFor(model => model.SettlementDate)  (Ex.31/12/2014)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Unit<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Unit, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(@Model.Unit) })
                            @Html.ValidationMessageFor(model => model.Unit)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Price / Unit<span class="error"> * </span>:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.PriceUnit, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.PriceUnit) })
                            @Html.ValidationMessageFor(model => model.PriceUnit)</td>
                        <td>
                            <div align="right">Gross Amount<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.GrossAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Transaction.GrossAmount) })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">COM<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.ComRate, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.ComRate) })
                            @Html.ValidationMessageFor(model => model.ComRate) (%)</td>
                        <td>
                            <div align="right">COM AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.ComAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Transaction.ComAmount) })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">VAT Rate<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.VatRate, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.VatRate) })
                            @Html.ValidationMessageFor(model => model.VatRate) (%)</td>
                        <td>
                            <div align="right">VAT AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.VatAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Transaction.VatAmount) })</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;&nbsp;</td>
                        <td>
                            <div align="right">Purchase Value (Net)<span class="error"></span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.Transaction.PurchaseValueNet, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Transaction.PurchaseValueNet) })</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">W/H TAX Rate<span class="error"> * </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.WHTaxRate, new { @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.WHTaxRate) })
                            @Html.ValidationMessageFor(model => model.WHTaxRate)
                            &nbsp;(%)</td>
                        <td>
                            <div align="right">W/H TAX AMOUNT<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Transaction.WHTaxAmount, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Transaction.WHTaxAmount) })
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;&nbsp;</td>
                        <td>
                            <div align="right">Net Settle AMT. incl W/T<span class="error"> </span>: </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                        @Html.TextBoxFor(model => model.Transaction.NetSettle, new { @readonly = "readonly", @class = "inputNumberField", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency2(@Model.Transaction.NetSettle) })
                    </tr>

                    <tr>
                        <td style="height: 4px">&nbsp;</td>
                        <td style="height: 4px"></td>
                        <td style="width: 236px; height: 4px;"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                        <td style="height: 4px"></td>
                    </tr>
                </table>

                <table width="95%" height="85" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center">

                                <input id="SubmitBtn" type="submit" name="SubmitBtn" value=" Submit " need-confirm="true" class="button" />
                                &nbsp;&nbsp; 
                                <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button" />
                            </div>
                        </td>
                    </tr>

                </table>


    
                @Html.HiddenFor(x => x.UpdateMode);
                @Html.HiddenFor(x => x.HeaderID);
                @Html.HiddenFor(x => x.TransactionID);

            }

        </td>
    </tr>
</table>
